﻿@inherits BaseComponent

<Space Class="kui-nav" Size="@("24")">
    <SpaceItem>
        <Tooltip Title="@Language["Nav.HomePage"]">
            <a href="/"><Icon Type="home" /></a>
        </Tooltip>
    </SpaceItem>
    <SpaceItem Class="kui-nav-full">
        <Tooltip Title="@FullScreenTitle"><Icon Type="@FullScreenIcon" OnClick="OnFullScreen" /></Tooltip>
    </SpaceItem>
    @if (Config.App.IsLanguage)
    {
        <SpaceItem Style="width:40px;text-align:center;">
            <AntLanguage OnChanged="OnLanguageChanged" />
        </SpaceItem>
    }
    <SpaceItem>
        <AntDropdown Context="Context" Text="@CurrentUser?.Name" Items="UserItems" OnItemClick="e=>OnItemClick(e.Id)" />
    </SpaceItem>
    @if (Config.App.IsTheme)
    {
        <SpaceItem>
            <AntTheme Theme="@Context.Theme" OnChanged="SetTheme" />
        </SpaceItem>
    }
    <SpaceItem Class="kui-nav-setting">
        <Tooltip Title="@Language["Nav.Setting"]"><Icon Type="setting" OnClick="@(e=>OnItemClick("setting"))" /></Tooltip>
    </SpaceItem>
</Space>

@code {
    private bool isFullScreen = false;
    private string FullScreenTitle => isFullScreen ? Language["Nav.ExitScreen"] : Language["Nav.FullScreen"];
    private string FullScreenIcon => isFullScreen ? "fullscreen-exit" : "fullscreen";
    private List<ActionInfo> UserItems => [
        new ActionInfo { Id = "profile", Name = Language["Nav.Profile"], Icon = "user", Url = "/profile" },
        new ActionInfo { Id = "logout", Name = Language["Nav.Exit"], Icon = "poweroff" }
    ];

    [Parameter] public Action<string> OnMenuClick { get; set; }

    private void OnItemClick(string id) => OnMenuClick?.Invoke(id);

    private async void OnFullScreen()
    {
        isFullScreen = !isFullScreen;
        if (isFullScreen)
            await JS.OpenFullScreenAsync();
        else
            await JS.CloseFullScreenAsync();
    }

    private void OnLanguageChanged() => App?.StateChanged();

    private void SetTheme(string theme)
    {
        if (!Config.App.IsTheme)
            return;

        Context.Theme = theme;
        StateChanged();
    }
}